package top.yxqz.req;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 * @author Mr.余
 * @date 2022/11/21
 * @package top.yxqz.req
 * 常用的方法
 */

@WebServlet("/demo1")
public class ReqDemo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();

        //        获取应用上下文
        String contextPath = request.getContextPath();
        writer.println("应用上下文："+contextPath);

        Cookie[] cookies = request.getCookies();
        writer.println("</br>Cookies："+ Arrays.toString(cookies));

//        getRequesURI包括了应用上下文的
        String uri = request.getRequestURI();
        writer.println("</br>uri："+uri);

        StringBuffer requestURL = request.getRequestURL();
        writer.println("</br>URL："+requestURL);

        String method = request.getMethod();
        writer.println("</br>请求的方法："+method);

        String pathInfo = request.getPathInfo();
        writer.println("</br>其他路径信息："+pathInfo);



    }


}
